home *** CD-ROM | disk | FTP | other *** search
- /* =================
- * PedApplication.cc
- * =================
- */
-
- #include "PedestalDebugging.h"
-
- #include <DiskInit.h>
- #include <Menus.h>
- #include <ToolUtils.h>
- #include <Windows.h>
-
- #include "PedApplication.hh"
-
- // Apple Event Assistant classes.
- #include "AEARegistry.h"
- #include "AEAHandlerGetData.hh"
- #include "AEAAccessorWildFromNull.hh"
- #include "AEAAccessorWildFromList.hh"
- #include "AEAAccessorModelFromWild.hh"
- #include "AEAModelName.hh"
-
- // Pedestal classes
- #include "Ped1AppProcess.hh"
- #include "PedHandlerOpenApp.hh"
- #include "PedHandlerQuit.hh"
- #include "PedWindow.hh"
- #include "PedAgent.hh"
- #include "PedAgentAboutBox.hh"
- #include "PedChore.hh"
-
- // Xtep classes
- #include "XAutoReleasePoolObj.hh"
-
-
- PedApplication::PedApplication()
- : PedTask(NULL), mProcess(Ped1AppProcess::Me()), mModel(*this)
- , mAboutCmd(*this), mNewCmd(*this), mOpenCmd(*this), mQuitCmd(*this)
- , mPreInitDone(false), mOpenAppReceived(false), mOpenDocReceived(false)
- , mQuitReceived(false)
- {
- SetName("Pedestal");
- }
-
- PedApplication::~PedApplication()
- {
-
- }
-
- void
- PedApplication::InstallAECallbacks(AEAModelRoot &inAppModel)
- {
- new PedHandlerOpenApp(*this);
- //new CAEAOpenDocHandler;
- new PedHandlerQuit(*this);
-
- new AEAHandlerGetData;
-
-
- // Accesses of anything from null get redispatched as from the application.
- new AEAAccessorWildFromNull(inAppModel);
- // Accesses of anything from a list get redispatched for each item.
- new AEAAccessorWildFromList;
- // Access a property from a model object.
- new AEAAccessorModelFromWild(cProperty, typeModelToken);
- }
-
- void
- PedApplication::InstallMenuCommands()
- {
- mMenuBar.AppleMenu().InstallCommand(&mAboutCmd, 'abou');
- mMenuBar.FileMenu().InstallCommand(&mNewCmd, 'new ');
- mMenuBar.FileMenu().InstallCommand(&mOpenCmd, 'open');
- mMenuBar.FileMenu().InstallCommand(&mCloseCmd, 'clos');
- mMenuBar.FileMenu().InstallCommand(&mQuitCmd, 'quit');
- //mMenuBar.EditMenu().InstallCommand(&mUndoCmd, 'undo');
- mMenuBar.EditMenu().InstallCommand(&mCutCmd, 'cut ');
- mMenuBar.EditMenu().InstallCommand(&mCopyCmd, 'copy');
- mMenuBar.EditMenu().InstallCommand(&mPasteCmd, 'pste');
- mMenuBar.EditMenu().InstallCommand(&mClearCmd, 'clea');
- //mMenuBar.EditMenu().InstallCommand(&mSelectAllCmd, 'slct');
- }
-
- void
- PedApplication::MyPreInit()
- {
- InstallAECallbacks(mModel);
- InstallMenuCommands();
- }
-
- void
- PedApplication::PreInit()
- {
- if (!mPreInitDone) {
- MyPreInit();
- mPreInitDone = true;
- }
- }
-
- void
- PedApplication::Initialize()
- {
- PreInit();
- }
-
- /*
- * --------------------------
- * Event processing routines.
- * --------------------------
- */
-
- void
- PedApplication::DispatchNullEvent(EventRecord &inEvent)
- {
- WindowPtr window = ::FrontWindow();
- WindowPeek peek = (WindowPeek)window;
- if (peek && peek->windowKind == kPedestalWindowKind)
- ((PedWindow *)GetWRefCon(window))->DispatchNullEvent(inEvent);
- }
-
- void
- PedApplication::DispatchHighLevelEvent(EventRecord &inEvent)
- {
- OSErr err = ::AEProcessAppleEvent(&inEvent);
- }
-
- void
- PedApplication::DispatchMouseDown(EventRecord &inEvent)
- {
- WindowPtr window;
- Rect dragRect;
-
- if (inEvent.what != mouseDown)
- return;
-
- switch (::FindWindow(inEvent.where, &window)) {
- case inSysWindow:
- ::SystemClick(&inEvent, window);
- break;
- case inMenuBar:
- mMenuBar.ProcessMenuItem(::MenuSelect(inEvent.where));
- break;
- case inDrag:
- dragRect = qd.screenBits.bounds;
- ::DragWindow(window, inEvent.where, &dragRect);
- break;
- case inContent:
- //::GlobalToLocal(&inEvent.where);
- //WindowClick(window, inEvent.where);
- if (((WindowPeek)window)->windowKind == kPedestalWindowKind)
- ((PedWindow *)GetWRefCon(window))->DispatchClickEvent(inEvent);
- break;
- case inGrow:
- Rect sizeRect = {30, 50, 10000, 10000};
- long dims = ::GrowWindow(window, inEvent.where, &sizeRect);
- if (dims)
- if (((WindowPeek)window)->windowKind == kPedestalWindowKind)
- ((PedWindow *)GetWRefCon(window))->Resize(LoWord(dims), HiWord(dims));
- else
- ::SizeWindow(window, LoWord(dims), HiWord(dims), true);
- break;
- case inGoAway:
- if (((WindowPeek)window)->windowKind == kPedestalWindowKind)
- ((PedWindow *)GetWRefCon(window))->ProcessGoAway(inEvent);
- break;
- default:
- break;
- }
- }
-
- void
- PedApplication::DispatchKey(EventRecord &inEvent)
- {
- if (inEvent.modifiers & cmdKey) {
- if (inEvent.what == keyDown) // no commands on autoKey
- mMenuBar.ProcessMenuItem(::MenuKey(inEvent.message & charCodeMask));
- } else {
- WindowPtr window = ::FrontWindow();
- WindowPeek peek = (WindowPeek)window;
- if (peek != NULL && peek->windowKind == kPedestalWindowKind)
- ((PedWindow *)GetWRefCon(window))->DispatchKey(inEvent);
- }
- }
-
- void
- PedApplication::DispatchActivate(EventRecord &inEvent)
- {
- if (inEvent.what != activateEvt)
- return;
-
- if (((WindowPeek)inEvent.message)->windowKind == kPedestalWindowKind) {
- PedWindow *wind = (PedWindow *)GetWRefCon(WindowPtr(inEvent.message));
- if (inEvent.modifiers & activeFlag) {
- wind->Activate();
- } else {
- wind->Deactivate();
- }
- }
-
- }
-
- void
- PedApplication::DispatchUpdate(EventRecord &inEvent)
- {
- if (inEvent.what != updateEvt)
- return;
-
- //::BeginUpdate(WindowPtr(inEvent.message));
- if (((WindowPeek)inEvent.message)->windowKind == kPedestalWindowKind)
- ((PedWindow *)GetWRefCon(WindowPtr(inEvent.message)))->Update();
- //::EndUpdate(WindowPtr(inEvent.message));
- }
- void
- PedApplication::DispatchDiskInsert(EventRecord &inEvent)
- {
- if (inEvent.what != updateEvt)
- return;
- if (HiWord(inEvent.message) == 0)
- return;
-
- Point pt = {100, 100};
-
- ::DILoad();
- ::DIBadMount(pt, inEvent.message);
- ::DIUnload();
- }
-
-
- void
- PedApplication::DispatchEvent(EventRecord &inEvent)
- {
- switch (inEvent.what) {
- case nullEvent:
- DispatchNullEvent(inEvent);
- break;
- case kHighLevelEvent:
- DispatchHighLevelEvent(inEvent);
- break;
- case mouseDown:
- DispatchMouseDown(inEvent);
- break;
- case keyDown:
- case autoKey:
- DispatchKey(inEvent);
- break;
- case activateEvt:
- DispatchActivate(inEvent);
- break;
- case updateEvt:
- DispatchUpdate(inEvent);
- break;
- case diskEvt:
- DispatchDiskInsert(inEvent);
- break;
- default:
- break;
- }
- }
-
- void
- PedApplication::EventLoop()
- {
- EventRecord evt;
- long sleepTicks = 10;
- RgnHandle mouseRgn = NULL;
-
- XAutoReleasePoolObj pool;
-
- // Use two levels of looping.
- // This lets us loop inside the try block without entering and leaving,
- // and will continue looping if an exception is thrown.
- while (!mQuitReceived) {
- try {
- while (!mQuitReceived) {
- pool.Flush();
- DoRepeatChores();
- if (::WaitNextEvent(everyEvent, &evt, sleepTicks, mouseRgn)) {
- DispatchEvent(evt);
- } else {
- DispatchNullEvent(evt);
- DoIdleChores();
- }
- if (mOpenDocReceived && !mOpenAppReceived) {
- mQuitReceived = true;
- }
- }
- } catch (...) {
- DebugBeep();
- }
- }
- }
-
- void
- PedApplication::Run()
- {
- Initialize();
- EventLoop();
- }
-
- void
- PedApplication::NotifyOpenAppEvent()
- {
- mOpenAppReceived = true;
- }
-
- void
- PedApplication::NotifyOpenDocEvent()
- {
- mOpenDocReceived = true;
- }
-
- void
- PedApplication::NotifyPrintDocEvent()
- {
- mOpenDocReceived = true;
- }
-
- void
- PedApplication::NotifyQuitEvent()
- {
- mQuitReceived = true;
- }
-
- void
- PedApplication::DoAbout()
- {
- mAboutBox.OpenWindow();
- }
-